package com.demo.petshop.controller;

import com.demo.petshop.entity.VideoComments;
import com.demo.petshop.service.VideoCommentsService;
import com.mybatisflex.core.paginate.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 *  控制层。
 *
 * @author lenovo
 * @since 2025-06-11
 */
@RestController
@RequestMapping("/videoComments")
public class VideoCommentsController {

    @Autowired
    private VideoCommentsService videoCommentsService;

    @PostMapping("save")
    public boolean save(@RequestBody VideoComments videoComments) {
        return videoCommentsService.save(videoComments);
    }

    /**
     * 根据主键删除。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    public boolean remove(@PathVariable Serializable id) {
        return videoCommentsService.removeById(id);
    }

    @PutMapping("update")
    public boolean update(@RequestBody VideoComments videoComments) {
        return videoCommentsService.updateById(videoComments);
    }

    /**
     * 查询所有。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    public List<VideoComments> list() {
        return videoCommentsService.list();
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id 主键
     * @return 详情
     */
    @GetMapping("getInfo/{id}")
    public VideoComments getInfo(@PathVariable Serializable id) {
        return videoCommentsService.getById(id);
    }

    /**
     * 分页查询。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    public Page<VideoComments> page(Page<VideoComments> page) {
        return videoCommentsService.page(page);
    }

    @GetMapping("addComment")
    public Object addComment(@RequestParam Integer videoId, @RequestParam String content){
        return videoCommentsService.addComment(videoId, content);
    }

    @PostMapping("like")
    public Object like(@RequestParam Integer commentId) {
        return videoCommentsService.like(commentId);
    }
}
